import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '../views/Layout.vue'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Layout,
    redirect: '/home',
    meta: {
      title: '聚合空间'
    },
    children: [
      {
        path: '/home',
        name: 'Home',
        component: Home,
        meta: {
          title: '聚合空间'
        },
      },
      {
        path: '/video',
        name: 'Video',
        meta: {
          title: '聚合空间'
        },
        component: () => import('@/views/Video.vue'),
      },
      {
        path: '/picture',
        name: 'Picture',
        meta: {
          title: '聚合空间'
        },
        component: () => import('@/views/Picture.vue'),
      },
      {
        path: '/detail',
        name: 'Detail',
        meta: {
          title: '视频详情'
        },
        component: () => import('@/views/Detail.vue'),
      },
    ]
  },
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  // 设置网页标题
  if (to.meta.title) {
    document.title = to.meta.title;
  }
  next();
});

export default router
